import message
import os
import sys

def use_import():
    """
    完成包的使用
    :return:
    """
    message.send_message.message_send('你好')
    text = message.receive_message.message_receive()
    print(text)



def open_r(file_name):
    """
    完成文件的文本模式的读，写
    :return:
    """
    # 读文件
    file = open(file_name,mode='r',encoding='utf-8')
    text = file.read()
    print(text)
    file.close()
def open_rw(file_name):
    file = open(file_name,mode='r+',encoding='utf-8')
    file.write('这是修改后的文本')
    file.close()

def open_w(file_name):
    file = open(file_name,mode='w',encoding='utf-8')
    file.write('\nw模式下添加的文本')

def open_a(file_name):
    file = open(file_name,mode='a',encoding='utf-8')
    file.write('\na模式下添加的文本')
    file.close()

def use_dir():
    file_list = os.listdir('.')
    print(file_list)
    print(os.getcwd())
    os.chdir('dir2')

def use_sys(file_path):
    file = open(file_path,mode='w+',encoding='utf-8')
    file.write('添加文本')
    file.close()


if __name__ == '__main__':
    #包的使用
    use_import()
    print('-'*50)
    #完成文件的文本模式的读，写
    open_r('test.txt')
    open_rw('test.txt')
    open_w('test.txt')
    open_a('test.txt')
    print('-'*50)
    #完成目录的listdir，getcwd,chdir的使用
    use_dir()
    print('-'*50)
    #完成python的传参练习
    use_sys(sys.argv[1])
